package duckHunter.sprites;




import java.io.IOException;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.media.MediaException;

import duckHunter.app.ApplicationResource;
import duckHunter.ui.Level1;
import duckHunter.ui.SoundPlayer;
/**
 *CanardSprite extends Sprite class 
 * @author AYARI
 *
 */

public class CanardSprite extends Sprite {
	//private integer initial; 
	private int deltaX;

	//class to play sound;
	SoundPlayer player = new SoundPlayer("/audio/canard.wav");

	/** Constructor **/
	public CanardSprite(Image image, int frameWidth, int frameHeight, int deltaX) {
		super(image);
		defineReferencePixel(frameWidth / 2, frameHeight / 2);
		this.deltaX= deltaX;
		playMidi();
	}
	
	/** 
	 * move the sprite vertically in the range of the screen width
	 **/
	public void moveSprite(int w, int h) throws MediaException {
		// recover sprite position
		int x = getX();
		if (x+getWidth() >= w - 1 || x <= 1){
			deltaX = -deltaX;
		}
		//setting the position
		x += deltaX;
		setPosition(x, getY());
		
	}
	
	// play an explosion sound
	public void playMidi() {
		try {
			player.play();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (MediaException e) {
			e.printStackTrace();
		}
	}
}
